const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('m_wechat_user', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      comment: 'autoid'
    },
    tenant_id: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '租户id'
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '系统用户id'
    },
    openid: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: '微信用户openid',
      unique: 'idx_openid'
    },
    appid: {
      type: DataTypes.STRING(45),
      allowNull: true,
      defaultValue: '',
      comment: '公众号id'
    },
    nickname: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '微信昵称'
    },
    sex: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '0未知,1男性,2女性'
    },
    language: {
      type: DataTypes.STRING(45),
      allowNull: true,
      comment: '语言'
    },
    city: {
      type: DataTypes.STRING(45),
      allowNull: true,
      comment: '城市'
    },
    province: {
      type: DataTypes.STRING(45),
      allowNull: true,
      comment: '省'
    },
    country: {
      type: DataTypes.STRING(45),
      allowNull: true,
      comment: '国家'
    },
    headimgurl: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '头像url'
    },
    privilege: {
      type: DataTypes.STRING(45),
      allowNull: true,
      comment: '微信特权'
    },
    unionid: {
      type: DataTypes.STRING(45),
      allowNull: true,
      comment: '开放平台id'
    },
    create_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '创建时间'
    },
    modify_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '修改时间'
    }
  }, {
    sequelize,
    tableName: 'm_wechat_user',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' }
        ]
      },
      {
        name: 'idx_openid',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'openid' }
        ]
      },
      {
        name: 'idx_tenant_id',
        using: 'BTREE',
        fields: [
          { name: 'tenant_id' }
        ]
      },
      {
        name: 'idx_user_id',
        using: 'BTREE',
        fields: [
          { name: 'user_id' }
        ]
      }
    ]
  });
};
